package com.zzzy.server.controller;

import com.zzzy.common.vo.AjaxResult;
import com.zzzy.sys.service.UserService;
import com.zzzy.sys.vo.profile.UserProfileUpdateReq;
import com.zzzy.sys.vo.profile.UserUpdatePasswordReq;
import com.zzzy.sys.vo.user.UserInfoRes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Tag(name = "用户个人中心", description = "server002")
@RestController
@Validated
@RequestMapping("/user/profile")
public class UserProfileController {

    @Resource
    private UserService userService;

    @GetMapping("/getUserProfile")
    @Operation(summary = "获得登录用户信息")
    public AjaxResult<UserInfoRes> getUserProfile() {
        UserInfoRes userInfoRes = userService.getLoginUserInfo();
        return AjaxResult.success(userInfoRes);
    }

    @PutMapping("/updateUserProfile")
    @Operation(summary = "修改用户个人信息")
    public AjaxResult updateUserProfile(@Valid @RequestBody UserProfileUpdateReq updateReq) {
        userService.updateLoginUserInfo(updateReq);
        return AjaxResult.success();
    }

    @PutMapping("/updatePassword")
    @Operation(summary = "修改用户密码")
    public AjaxResult updatePassword(@Valid @RequestBody UserUpdatePasswordReq userUpdatePasswordReq) {
        userService.updateLoginUserPassword(userUpdatePasswordReq);
        return AjaxResult.success();
    }
}